package com.example.administrator.managesystem.presenter.profile;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import com.example.administrator.managesystem.activity.firstpage.circle.ui.SendCircleActivity;
import com.example.administrator.managesystem.bean.CollectBean;
import com.example.administrator.managesystem.bean.CollectCircleBean;
import com.example.administrator.managesystem.bean.CollectWikiBean;
import com.example.administrator.managesystem.bean.RepostBean;
import com.example.administrator.managesystem.bean.ShareCircleBean;
import com.example.administrator.managesystem.bean.ShareWikiBean;
import com.example.administrator.managesystem.bean.WikiDetailBean;
import com.example.administrator.managesystem.network.GuideAPI;
import com.example.administrator.managesystem.network.ServiceManager;
import com.example.administrator.managesystem.ui.MyCollectView;
import com.example.administrator.managesystem.ui.MyShareView;
import com.example.administrator.managesystem.utils.ToastUtils;

import java.io.IOException;

import okhttp3.ResponseBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class MyCollectPresenter {

    private MyCollectView myCollectView;

    public MyCollectPresenter(MyCollectView myCollectView) {
        this.myCollectView = myCollectView;
    }

    public void wikiListRequest(String user_id, String token, final int page, int pageSize, final String request_type, final int type, final Context context){
        ServiceManager.getInstance(context).getService(GuideAPI.class).myCollectWikiRequest(user_id,token,page,pageSize, request_type)
                .subscribeOn(Schedulers.io())//IO线程加载数据
                .observeOn(AndroidSchedulers.mainThread())//主线程显示数据
                .subscribe(new Subscriber<CollectWikiBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.showToast(context,t.getMessage());
                    }

                    @Override
                    public void onNext(CollectWikiBean collectWikiBean) {
                       if(collectWikiBean.getStatus()==200){
                           myCollectView.showCollectWikiList(collectWikiBean.getData(),type);
                       }
                    }

                });
    }

    public void circleListRequest(String user_id, String token, final int page, int pageSize, final String request_type, final int type, final  Context context){
        ServiceManager.getInstance(context).getService(GuideAPI.class).myCollectCircleRequest(user_id,token,page,pageSize, request_type)
                .subscribeOn(Schedulers.io())//IO线程加载数据
                .observeOn(AndroidSchedulers.mainThread())//主线程显示数据
                .subscribe(new Subscriber<CollectCircleBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.showToast(context,t.getMessage());
                    }

                    @Override
                    public void onNext(CollectCircleBean collectCircleBean) {
                               if(collectCircleBean.getStatus()==200){
                                   myCollectView.showCollectCircleList(collectCircleBean.getData(),type);
                               }
                    }

                });
    }

    public void wikiDetailRequest(String user_id,String wiki_id,final Context context){
        ServiceManager.getInstance(context).getService(GuideAPI.class).wikiDetailRequest(wiki_id,user_id)
                .subscribeOn(Schedulers.io())//IO线程加载数据
                .observeOn(AndroidSchedulers.mainThread())//主线程显示数据
                .subscribe(new Subscriber<WikiDetailBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.showToast(context,t.getMessage());
                    }

                    @Override
                    public void onNext(WikiDetailBean wikiDetailBean) {
                        if(wikiDetailBean.getStatus()==200){
                           myCollectView.showWikiDetail(wikiDetailBean.getData());
                        }
                    }

                });
    }

    public void collectRequest(String user_id, String breeding_id, String token, final ImageView imageView, final Context context){
        ServiceManager.getInstance(context).getService(GuideAPI.class).CollectCircleRequest(user_id,breeding_id,token)
                .subscribeOn(Schedulers.io())//IO线程加载数据
                .observeOn(AndroidSchedulers.mainThread())//主线程显示数据
                .subscribe(new Subscriber<CollectBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.showToast(context,t.getMessage());
                    }

                    @Override
                    public void onNext(CollectBean collectBean) {
                        if(collectBean.getStatus()==200){
                            ToastUtils.showToast(context,collectBean.getData());
                            myCollectView.showSuccess(imageView);
                        }
                    }

                });
    }
    public void repostRequest(String user_id, String breeding_id, String token, final int type, final  Context context){
        ServiceManager.getInstance(context).getService(GuideAPI.class).shareWikiRequest(user_id,breeding_id,token)
                .subscribeOn(Schedulers.io())//IO线程加载数据
                .observeOn(AndroidSchedulers.mainThread())//主线程显示数据
                .subscribe(new Subscriber<RepostBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.showToast(context,t.getMessage());
                    }

                    @Override
                    public void onNext(RepostBean repostBean) {
                        if(repostBean.getStatus()==200){
                           myCollectView.repost("",type);
                        }
                    }

                });
    }
}
